import pymysql


dbhost = 'localhost'
dbuser = 'root'
dbpass = 'ywh.2004430'
dbname = 'test'
db = pymysql.connect(host=dbhost, user=dbuser, password=dbpass, database=dbname)
cursor = db.cursor()

sql = "SELECT * FROM employee WHERE income > %s" % (1000)

try:
    cursor.execute(sql)
    results = cursor.fetchall()
    for row in results:
        fname = row[1]
        lname = row[2]
        age = row[3]
        sex = row[4]
        income = row[5]
        print("name=%s, lname=%s, age=%s, sex=%s, income=%s" % (fname, lname, age, sex, income))
except:
    import traceback
    traceback.print_exc()
    print("Error:unable to fetch data")
db.close()
